package cn.tradewin.advisor.pages.master;

import java.util.List;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import cn.tradewin.advisor.exceptions.DBException;
import cn.tradewin.advisor.persist.model.Job;
import cn.tradewin.advisor.persist.services.JobService;

public class JobBoard {
	
	@Inject
	private Messages messages;
	
	@Inject
	private BeanModelSource beanModelSource;
	
	@Property
	private BeanModel<Job> beanModel;
	
	@Property
	private List<Job> jobs;
	
	@Property
	private Job job;
	
	@Inject
	private JobService jobService;
	
	@SetupRender
	void setupRender() throws DBException {
		beanModel = beanModelSource.createDisplayModel(Job.class, messages);
		beanModel.add("action", null);
		beanModel.include("name", "desc", "action");
		beanModel.get("desc").sortable(false);
		beanModel.get("action").sortable(false);
	}	
	
	@OnEvent(EventConstants.PREPARE_FOR_RENDER)
	void onPrepareForRender() throws DBException {
		jobs = jobService.getAllJobs();
	}
	
	void onDelete(String jobId) {
		jobService.delJob(jobId);
	}
}
